package com.ruoyi.recycle.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.recycle.domain.ClientCoupon;
import com.ruoyi.recycle.domain.Coupon;
import com.ruoyi.recycle.dto.ClientCouponDTO;
import com.ruoyi.recycle.mapper.ClientCouponMapper;
import com.ruoyi.recycle.service.ClientCouponService;
import com.ruoyi.recycle.vo.CouponVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


@Service
public class ClientCouponServiceImpl extends ServiceImpl<ClientCouponMapper, ClientCoupon> implements ClientCouponService {

    @Resource
    private ClientCouponMapper clientCouponMapper;

    @Override
    public AjaxResult myCoupon(ClientCouponDTO clientCouponDTO) {
        List<CouponVo> couponList = new ArrayList<>();
        if (clientCouponDTO.getStatus() == 0){
            couponList = clientCouponMapper.selectMyCouponBy0(clientCouponDTO.getClientId());
        }else if (clientCouponDTO.getStatus() == 1){
            couponList = clientCouponMapper.selectMyCouponBy1(clientCouponDTO.getClientId());
        }else if (clientCouponDTO.getStatus() == 2){
            couponList = clientCouponMapper.selectMyCouponBy2(clientCouponDTO.getClientId());
        }
        List<CouponVo> subList = couponList.stream().skip((clientCouponDTO.getCurrentPage()-1)*clientCouponDTO.getPageSize()).limit(clientCouponDTO.getPageSize()).collect(Collectors.toList());

        return AjaxResult.success(subList).put("total",couponList.size()).put("currentPage",clientCouponDTO.getCurrentPage());
    }


}
